<template>
    <div class="edit-popup">
        <popup ref="popupRef" :title="popupTitle" :async="true" width="1000px" :footer="false">
            <el-tabs v-model="activeName">
                <el-tab-pane label="流程信息" name="first">
                    <el-form :inline="true" ref="formRef" class="mb-[-16px]">
                        <el-form-item prop="type" label="流程类型">
                            <el-input v-model="formData.type" class="w-[775px]" disabled />
                        </el-form-item>
                        <el-form-item prop="name" label="部门信息">
                            <el-input v-model="deptData" class="w-[775px]" disabled />
                        </el-form-item>
                    </el-form>
                    <el-tabs v-model="activeNames">
                        <el-tab-pane label="专利" name="patent">
                            <flow :formData="formData" :isAdd="isAdd" :formTitle="zhuanli" />
                        </el-tab-pane>
                        <el-tab-pane label="商标" name="brand"> 2 </el-tab-pane>
                        <el-tab-pane label="版权" name="copyright"> 3 </el-tab-pane>
                    </el-tabs>
                </el-tab-pane>
            </el-tabs>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import flow from './component/flow.vue'

import { flowDelete, deptFlowDetail } from '@/api/deptFlow'
import Popup from '@/components/popup/index.vue'
import { useDictOptions } from '@/hooks/useDictOptions'
import feedback from '@/utils/feedback'
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const deptData = ref('基础信息')
const popupTitle = computed(() => {
    return mode.value == 'edit' ? '流程编辑' : '流程信息'
})
const formData = reactive({
    depId: '',
    type: '',
    proposalType: '',
    configProposal: '',
    isBasics: '',
    flowNode: {
        isValid: '',
        proposalType: '',
        isFlow: '',
        isBackNode: ''
    },
    nodes: []
})
const activeName = 'first'
const activeNames = 'patent'
const isAdd = ref(true)
const flowtype = ref('')
const zhuanli = ref('专利')

const open = async (type = 'add', flow: any) => {
    mode.value = type
    formData.type = flow
    popupRef.value?.open()
    if (mode.value === 'add') {
        deptData.value = '基础流程'
        const data = await deptFlowDetail({
            isBasics: '是'
        })
        console.log(data, '2222')
    }
}

const setFormData = (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}
const getDetail = async (row: Record<string, any>, type: any) => {
    if (row.deptFlow != null || row.deptFlow != undefined) {
        isAdd.value = false
        const data = await deptFlowDetail({
            depId: row.id,
            type: type
        })
        setFormData(data)
    }
    flowtype.value = type
    formData.depId = row.id
    formData.type = type
    deptData.value = row.name
}

const handleClose = () => {
    emit('close')
}

defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
